//
//  SQPointsViewController.m
//  pai
//
//  Created by pro on 14-11-12.
//  Copyright (c) 2014年 linjunjing. All rights reserved.
//

#import "SQPointsViewController.h"
#import "SQPointsRuleViewController.h"

@interface SQPointsViewController ()

@end

@implementation SQPointsViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setTitle:@"积分记录"];
    
    [self initList];
}

-(void)initList
{
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, self.MyNavigationBar.frame.origin.y+self.MyNavigationBar.frame.size.height, 320, [[UIScreen  mainScreen] bounds].size.height - 44 - self.MyNavigationBar.frame.origin.y-self.MyNavigationBar.frame.size.height)];
    [self.view addSubview:_scrollView];
    _scrollView.delegate = self;
    _scrollView.pagingEnabled = NO;
    _scrollView.scrollEnabled = YES;
    
    _plv = [SQPointListView initmyview];
    _plv.frame = CGRectMake(0, 0, 320, 200);
    _plv.delegate = self;
    [_scrollView addSubview:_plv];
    
    [self getInfo];
}
-(void)getInfo
{
    my_stuff_t stuff;
    stuff.base.msgtype = 1030;
    stuff.base.len = sizeof(stuff);
    stuff.base.error = 0;
    stuff.type = 6001;
    strcpy(stuff.serialnum, "");
    strcpy(stuff.username, [[Global instance].userinfo.username UTF8String]);
    
    NSMutableData* msgData = [NSMutableData data];
    [msgData appendBytes:&stuff length:sizeof(stuff)];
    
    [super sendData:msgData tag:1 withHUD:YES];
}
-(void)getPointsInfo
{
    SQPointsRuleViewController* prvc = [[SQPointsRuleViewController alloc]init];
    [self.navigationController pushViewController:prvc animated:YES];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//读取数据
-(void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
{
    NSLog(@"get %ld",tag);
    if (tag == 1) {
        ack_my_stuff_t baseInfo;
        [data getBytes:&baseInfo length:sizeof(ack_my_stuff_t)];
        NSLog(@"%d",baseInfo.base.error);
        NSLog(@"%d",baseInfo.count);
        if (baseInfo.base.error == ACS_SUCCESS) {
            assets_t asset;
            [data getBytes:&asset range:NSMakeRange(data.length - sizeof(asset) - 8,sizeof(asset))];
            _plv.nowPointsLabel.text = [NSString stringWithFormat:@"%d",asset.points];
        }
        [self.HUD showAnimated:YES whileExecutingBlock:^{
            [self.HUD show:NO];
        } completionBlock:^{
        }];
    }
}
@end
